﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public class MTreeNode
    {
        public Object Data { get; set; }
        public List<MTreeNode> Childrens { get; private set; } = new List<MTreeNode>();
        public int Level { get; set; }

    }
    public class MultiTree
    {
        Stack<MTreeNode> t_stack;
        Queue<MTreeNode> queue_t = new Queue<MTreeNode>();

        private static MTreeNode SearchNode(object data, MTreeNode node)
        {
            MTreeNode temp = null;
            if (node == null)
                return null;

            if (node.Data.Equals(data))
            {
                temp = node;
            }
            else
            {
                foreach (var c in node.Childrens)
                {
                    temp = SearchNode(data, c);
                }
            }
            return temp;
        }

        public static void CreateTree_File(ref MTreeNode node)
        {

        }

        private static void f1(MTreeNode node)
        {
            //使用队列的方式完成了遍历
            MTreeNode tmTreeNode;
            Queue<MTreeNode> queue = new Queue<MTreeNode>(100);
            //Stack<MTreeNode> stack = new Stack<MTreeNode>(100);
            node.Level = 0;

            queue.Enqueue(node);

            while (queue.Count != 0)
            {
                tmTreeNode = queue.Dequeue();
                if (tmTreeNode.Childrens == null)
                    continue;

                foreach (var c in node.Childrens)
                {
                    c.Level = tmTreeNode.Level + 1;
                    queue.Enqueue(c);
                }
                //stack.Push(tmTreeNode);
            }

            //while (stack.Count != 0)
            //{
            //    tmTreeNode = stack.Pop();
            //}
        }

        
    }
}
